home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ASME's Mechanical Engine…ing Toolkit 1997 December
/
ASME's Mechanical Engineering Toolkit 1997 December.iso
/
c_lang
/
varinc.lzh
/
PAGE61.C
< prev
next >
Wrap
C/C++ Source or Header
|
1979-11-30
|
2KB
|
42 lines
/* Prompt for 3 long integer numbers and print their average. */
main()
{
double avg_3_longs(long, long, long); /* Declare subfunction. */
long first, second, third; /* Declare numbers prompted for. */
double average; /* Declare average of the numbers. */
printf("Enter 3 numbers: ");
/* Check scanf() return value for 3 good numbers. */
if (3 != scanf("%ld %ld %ld", &first, &second, &third))
printf("\nBad input data\7\n");
else /* Input data are OK, so proceed. */
{
average = avg_3_longs(first, second, third); /* Call. */
printf("\nThe average of %ld, %ld, and %ld is %f.\n",
first, second, third, average);
}
} /* end of the main() function */
/*****************************************************************************/
/* avg_3_longs() is a function that returns type double. */
/* The three parameters, all type long, are numbers to be averaged by */
/* totaling them and dividing by 3.0. */
/*****************************************************************************/
double avg_3_longs(long_one, long_two, long_three)
/* Parameters MUST be declared BEFORE the function's starting {, as follows: */
long long_one, long_two, long_three; /* Declare 3 longs to average. */
{
/* Non-parameter variables MUST be declared AFTER the function's */
/* starting {, as follows: */
double average; /* Holds computed average to return. */
average = ((long_one + long_two + long_three) / 3.0);
return (average); /* Return value to caller. */
}